from django.contrib import admin

# Register your models here.
from .models import *

from django.utils.safestring import mark_safe
from simpleui.admin import AjaxAdmin


@admin.register(Carousel)
class CarouselAdmin(AjaxAdmin):   
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
    upload_img.short_description = '走马灯图片'
    upload_img.allow_tags = True

    ordering = ('id', )
    # 要显示的字段
    list_display = ('id', 'upload_img')

@admin.register(ProductCategory)
class ProductCategoryAdmin(AjaxAdmin):
    ordering = ('id', )
    # 要显示的字段
    list_display = ('id', 'name')


@admin.register(Product)
class ProductAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
    upload_img.short_description = '产品展示图片'
    upload_img.allow_tags = True
    
    ordering = ('category', )
    # 要显示的字段
    list_display = ('category', 'upload_img')




@admin.register(DemoCategory)
class DemoCategoryAdmin(AjaxAdmin):
    ordering = ('id', )
    # 要显示的字段
    list_display = ('id', 'name')

@admin.register(DemoExample)
class DemoExampleAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '应用案例卡片图片'
    upload_img.allow_tags = True
    
    ordering = ('category', )
    # 要显示的字段
    list_display = ('category', 'synopsis',"upload_img","create_date")

@admin.register(DemoPicture)
class DemoPictureAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '应用案例卡片图片'
    upload_img.allow_tags = True
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id",'category', "upload_img")


@admin.register(DemoTopPicture)
class DemoTopPictureAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '关于应用案例顶部图片'
    upload_img.allow_tags = True
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id", "upload_img")

@admin.register(AboutUS)
class AboutUSAdmin(AjaxAdmin):
    def upload_img(self, obj):
        try:
            img = mark_safe('<img src="%s" height="120px" />' % (obj.imgUrl.url,))
        except Exception as e:
            img = ''
        return img
        
    upload_img.short_description = '关于我们图片'
    upload_img.allow_tags = True
    
    ordering = ("id", )
    # 要显示的字段
    list_display = ("id",'synopsis', "upload_img")


